<?php
/* @var $this BookController */
/* @var $model Book */

$this->breadcrumbs=array(
	'Books'=>array('index'),
	$model->id,
);
?>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl;?>/kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl;?>/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        KindEditor.ready(function(K) {
            editor = K.create('#message',{
            allowImageUpload : false,
            langType: "zh_CN",
            items : [
                "fontname", "fontsize", "|", "forecolor", "hilitecolor", "bold", "italic", "underline",
                "removeformat", "|", "justifyleft", "justifycenter", "justifyright", "insertorderedlist",
                "insertunorderedlist", "|", "emoticons", "image", "link"],
            });
        });
        $('#message-submit').click(function (){
            editor.sync();
            var message = $('#message').val();
            if(message == '')
            {
                alert('请输入评论');
            }
            else
            {
                $.ajax({
                    type: "GET",
                    url: "index.php?r=book/message",
                    data: {message:message, id:$("#bookid").val()},
                    dataType: "json",
                    success: function(data){
                        $('#messages-all').prepend("<h4><strong><a href='#'>"+<?php echo '"'.Yii::app()->user->name.'"';?>+"</a>      在" + currentTime() + "时说道:</strong></h4><blockquote>"+message+"</blockquote>");
                        editor.html('');
                    }
                    });
                }
        });
        $('#toVote').click(function (){
            var url='<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=book/vote';
            $.ajax({
                type: "GET",
                url:url,
                data: {id:<?php echo $model->id; ?>},
                success: function(data){
                    $('#toVote').val('投票'+data)
            }
            });
        });
    });
    function tenCompare(num){
        if(num < 9)
        {
            return '0'+num;
        }
        return num;
    }
    function currentTime(){
        var d = new Date(),str = '';
        str += d.getFullYear()+'-';
        str += tenCompare(d.getMonth() + 1)+'-';
        str += tenCompare(d.getDate())+' ';
        str += tenCompare(d.getHours())+':';
        str += tenCompare(d.getMinutes())+':';
        str += tenCompare(d.getSeconds());
        return str;
    }
</script>

<div class="container">
	<ol class="breadcrumb">
		<li><?php echo CHtml::link('首页', array('/site/index'));?></li>
		<li class="active"><?php echo CHtml::link('图书', array('/book/index'));?></li>
	</ol>

    <div class="row">
        <!-- Article main content -->
        <article class="col-md-10 maincontent">
			<header class="page-header">
				<h1 class="page-title">图书详情</h1>
			</header>
            <div class="row">
                <div class="col-md-4">
                    <?php echo '<img src="'.Yii::app()->request->baseUrl.'/images/'.$model->picture.'" style="height:300px;" />'; ?>
                </div>
                <div class="col-md-8">
                <?php $this->widget('zii.widgets.CDetailView', array(
                    'data'=>$model,
                    'attributes'=>array(
                        // 'id',
                        // array(
                                // 'label'=>'picture',
                                // 'type'=>'image',
                                // 'value'=>'./images/' . $model->picture,
                            // ),
                        array('label'=>'书名', 'value'=>$model->bookname),
                        array('label'=>'分类', 'value'=>$model->type->name),
                        array('label'=>'作者', 'value'=>$model->author),
                        array('label'=>'浏览次数', 'value'=>$model->browsertimes),
                        array('label'=>'简要', 'value'=>$model->abstract),
                        array('label'=>'投票支持','type'=>'raw', 'value'=>CHtml::button('投票'.$model->vote, array('id'=>'toVote'))),
                        array('label'=>'价格', 'value'=>$model->price),
                        // array('label'=>'详情', 'value'=>$model->content),
                        // array(
                                // 'label'=>'file',
                                // 'type'=>'url',
                                // 'value'=>CHtml::link(CHtml::encode($model->file->name), array('city/view','id'=>$model->file->name)),
                            // ),
                        // 'file',
                    ),
                )); ?>
                </div>
            </div>
            <?php echo $model->content; ?>
            <div id='messages-all'>
            <?php foreach(array_reverse($model->messages) as $value)
                {
                    echo "<h4><strong><a href='#'>".$value->user->username."</a>      在".$value->time."时说道:</strong></h4><blockquote>".$value->content."</blockquote>";
                }

            ?>
            </div>
            <input id='bookid' type='hidden' value='<?php echo $model->id; ?>'/>
            <input id='user' type='hidden' value='<?php echo Yii::app()->user->name; ?>'/>
            <textarea id='message' class='form-control'></textarea>
            <div class='text-right'>
                <input id='message-submit' class='btn btn-action' value='提交评论' type='submit'>
            </input>
        </article>
        <!-- /Article -->
        <!-- Sidebar -->
        <aside class="col-md-2 sidebar sidebar-right">

            <div class="row widget">
                <div class="col-xs-12">
                    <h5><?php echo CHtml::link('图书列表', array('/book/index'));?></h5>
                    <h5><?php echo CHtml::link('上传图书', array('/book/create'));?></h5>
                    <h5><?php echo CHtml::link('更新图书', array('/book/update', 'id'=>$model->id));?></h5>
                    <h5><?php echo CHtml::link(CHtml::encode('删除图书'), array('/book/delete', 'id'=>$model->id), array('submit'=>array('/book/delete', 'id'=>$model->id),'class'=>'delete','confirm'=>'确认删除图书吗?'));?></h5>
                    <h5><?php echo CHtml::link('管理图书', array('/book/admin'));?></h5>
                </div>
            </div>
            <div class="row widget">
                <div class="col-xs-12">
                    <p><img src="<?php echo Yii::app()->request->baseUrl; ?><?php echo Yii::app()->request->baseUrl; ?>/Progressus//assets/images/1.jpg" alt=""></p>
                </div>
            </div>
            <div class="row widget">
                <div class="col-xs-12">
                    <p><img src="<?php echo Yii::app()->request->baseUrl; ?><?php echo Yii::app()->request->baseUrl; ?>/Progressus//assets/images/2.jpg" alt=""></p>
                </div>
            </div>

        </aside>
        <!-- /Sidebar -->
    </div>
</div>
